package com.xinhe.web.controller;

import com.querydsl.core.QueryResults;
import com.xinhe.web.common.Result;
import com.xinhe.web.entity.TeamBuyOrder;
import com.xinhe.web.request.OrderByShopCartModel;
import com.xinhe.web.request.ServiceCenterQuery;
import com.xinhe.web.request.TeamBuyOrderModel;
import com.xinhe.web.response.TeamBuyOrderView;
import com.xinhe.web.response.TeamOrderByUserView;
import com.xinhe.web.service.AliyunService;
import com.xinhe.web.service.ServiceCenterService;
import com.xinhe.web.service.TeamBuyOrderService;
import com.xinhe.web.util.ValidatorUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

@Api(value = "拼团订单", tags = {"拼团订单"})
@RestController
@RequestMapping(value = {"/teamBuyOrder"}, produces = {"application/json;charset=UTF-8"})

public class TeamBuyOrderController {
    @Autowired
    private TeamBuyOrderService teamBuyOrderService;

    @ApiOperation(httpMethod = "GET", value = "分页查询拼团订单")
    @RequestMapping({"/pageTeamBuyOrder"})
    public QueryResults<TeamBuyOrderView> pageTeamBuyOrder(Long buyerUserId, Long teamGoodsId, Long goodsId, Long teamBuyId,
                                                           Long orderId, String status, int pageNum, int pageSize) {
        return this.teamBuyOrderService.pageTeamBuyOrder(buyerUserId,teamGoodsId,goodsId,teamBuyId,
                orderId,status,pageNum,pageSize);
    }

    @ApiOperation(httpMethod = "GET", value = "分页查询拼团订单（用户）")
    @RequestMapping({"/pageTeamOrderByUser"})
    public QueryResults<TeamOrderByUserView> pageTeamOrderByUser(Long buyerUserId,String status,int pageNum, int pageSize) {
        return this.teamBuyOrderService.pageTeamOrderByUser(buyerUserId, status, pageNum,  pageSize);
    }
    @ApiOperation(httpMethod = "POST", value = "保存拼团订单")
    @RequestMapping({"/saveTeamBuyOrder"})
    public Result saveTeamBuyOrder(@Valid TeamBuyOrderModel model) {
        return this.teamBuyOrderService.saveModel(model);
    }
    @ApiOperation(httpMethod = "POST", value = "发起团购")
    @RequestMapping({"/saveTeamOrderByLeader"})
    public Result saveTeamOrderByLeader(@Valid @RequestBody OrderByShopCartModel model) {
        return this.teamBuyOrderService.saveTeamOrderByLeader(model);
    }
    @ApiOperation(httpMethod = "POST", value = "加入团购")
    @RequestMapping({"/saveTeamOrderByMember"})
    public Result saveTeamOrderByMember(@Valid @RequestBody OrderByShopCartModel model) {
        return this.teamBuyOrderService.saveTeamOrderByMember(model);
    }

    @ApiOperation(httpMethod = "POST", value = "取消团购订单（已下单）")
    @RequestMapping({"/cancelTeamOrder"})
    public Result cancelTeamOrder(Long teamBuyOrderId) {
        return this.teamBuyOrderService.cancelTeamOrder(teamBuyOrderId);
    }

    @ApiOperation(httpMethod = "GET", value = "删除拼团订单")
    @ApiImplicitParam(name = "teamBuyOrderId", value = "标识", dataTypeClass = Long.class, required = true)
    @RequestMapping({"/deleteTeamBuyOrder"})
    public Result deleteTeamBuyOrder(Long teamBuyOrderId) {
        return this.teamBuyOrderService.delete(teamBuyOrderId);
    }
    @ApiOperation(httpMethod = "GET", value = "拼团订单详情")
    @ApiImplicitParam(name = "teamBuyOrderId", value = "标识", dataTypeClass = Long.class, required = true)
    @RequestMapping({"/detailTeamBuyOrder"})
    public Result detailTeamBuyOrder(Long teamBuyOrderId) {
        return this.teamBuyOrderService.detailTeamBuyOrder(teamBuyOrderId);
    }
    @ApiOperation(httpMethod = "GET", value = "拼团订单详情(订单id)")
    @RequestMapping({"/detailTeamOrderByOrderId"})
    public Result detailTeamOrderByOrderId(Long orderId) {
        return this.teamBuyOrderService.detailTeamOrderByOrderId(orderId);
    }
}
